package cn.qinhao.pethome.login.controller;

import cn.qinhao.pethome.basic.base.BaseConstants;
import cn.qinhao.pethome.basic.exception.BusinessException;
import cn.qinhao.pethome.basic.until.AjaxResult;
import cn.qinhao.pethome.login.domain.PhoneCodeVo;
import cn.qinhao.pethome.login.service.ImgCodeGeneratedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/imgCode")
public class ImgCodeGeneratedController {
    @Autowired
    private ImgCodeGeneratedService imgCodeGeneratedService;
    @GetMapping("/{uuid}")
    public String getimgCode(@PathVariable("uuid") String uuid){
        return imgCodeGeneratedService.getImgCode(uuid, BaseConstants.ImgCode.STATE_REGISTER);
    }
    //获取短信验证码
    @PostMapping
    public AjaxResult getPhoneCode(@RequestBody PhoneCodeVo phoneCodeVo){
        try {
            imgCodeGeneratedService.getPhoneCode(phoneCodeVo);
            return AjaxResult.me().setSuccess(true);
        } catch (BusinessException e) {
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("网络繁忙！！！");
        }
    }
}
